In [2]:
%matplotlib inline
from os.path import join

import pandas as pd
import numpy as np

import boris

In [3]:
subj_id = 'kre'
session_id = 'cafe'
subject = boris.BORISSubject(subj_id)

In [4]:
gaze_data = pd.HDFStore(subject.gaze_data_fpath(session_id), 'r')

In [5]:
session_gaze_data = gaze_data['task']
# session_gaze_data.sortlevel(axis=1, inplace=True)

In [6]:
task_df = session_gaze_data[~np.isnan(session_gaze_data['both', 'frame_time'])].copy()
task_df


Out[6]:
both left right
quality frame_time_diff frame_time frame_count flag href x href y pupil area pupil size flag href x href y pupil area pupil size
rep time
1 1653668 GOOD 1 1653667 3371 FIX -1958 -227 1909 0.623649 FIX -995 8 1403 0.629423
1653684 GOOD 1 1653683 3372 FIX -1973 -200 1920 0.625443 FIX -1013 62 1416 0.632332
1653716 GOOD 0 1653716 3373 FIX -2034 -126 1944 0.629340 FIX -1037 131 1431 0.635673
1653748 GOOD -1 1653749 3374 FIX -2075 -15 1969 0.633374 FIX -1112 250 1442 0.638111
1653784 GOOD 1 1653783 3375 FIX -2184 108 1977 0.634659 FIX -1171 264 1449 0.639658
1653816 GOOD 0 1653816 3376 FIX -2253 153 1983 0.635621 FIX -1233 405 1459 0.641862
1653848 GOOD -2 1653850 3377 FIX -2416 250 1994 0.637382 FIX -1362 494 1461 0.642302
1653884 GOOD 1 1653883 3378 FIX -2469 363 2019 0.641365 FIX -1376 624 1469 0.644058
1653916 GOOD 0 1653916 3379 FIX -2516 479 2040 0.644692 FIX -1376 788 1473 0.644934
1653948 GOOD -2 1653950 3380 SACC -2384 632 2044 0.645324 FIX -1344 921 1485 0.647556
1653976 GOOD -7 1653983 3381 SACC -2062 564 2008 0.639615 SACC -969 971 1479 0.646246
1654016 BAD 0 1654016 3382 SACC -935 3148 432 0.296674 SACC -661 2355 871 0.495933
1654048 BAD -1 1654049 3383 BLINK NaN NaN 0 0.000000 BLINK NaN NaN 0 0.000000
1654084 BAD 1 1654083 3384 BLINK NaN NaN 0 0.000000 BLINK NaN NaN 0 0.000000
1654116 BAD -1 1654117 3385 BLINK NaN NaN 0 0.000000 BLINK NaN NaN 0 0.000000
1654148 BAD -2 1654150 3386 BLINK NaN NaN 0 0.000000 BLINK NaN NaN 0 0.000000
1654184 BAD 1 1654183 3387 BLINK NaN NaN 0 0.000000 BLINK NaN NaN 0 0.000000
1654216 BAD 0 1654216 3388 BLINK NaN NaN 0 0.000000 NONE -610 4082 364 0.320601
1654248 BAD -1 1654249 3389 NONE 91 3828 756 0.392462 NONE 553 3189 1006 0.532982
1654284 BAD 1 1654283 3390 FIX -139 2372 1780 0.602209 NONE 790 2401 1487 0.647992
1654316 BAD 0 1654316 3391 FIX -239 2121 2121 0.657366 NONE 798 10951 1614 0.675096
1654348 BAD -1 1654349 3392 FIX -213 2392 2153 0.662307 FIX 775 11415 1615 0.675305
1654384 BAD 1 1654383 3393 FIX -123 2584 2176 0.665835 FIX 819 11478 1627 0.677809
1654416 BAD 0 1654416 3394 FIX 93 2626 2207 0.670561 FIX 927 11520 1655 0.683617
1654448 BAD -1 1654449 3395 FIX 278 2552 2248 0.676761 FIX 1027 11518 1697 0.692237
1654480 BAD -2 1654482 3396 SACC 766 2630 2283 0.682009 SACC 1354 11603 1707 0.694274
1654516 BAD 0 1654516 3397 SACC 4276 3885 2135 0.659532 SACC 3510 12583 1888 0.730155
1654548 BAD -2 1654550 3398 FIX 4499 3815 2121 0.657366 FIX 3761 12643 1990 0.749619
1654584 BAD 1 1654583 3399 FIX 4378 4061 2126 0.658141 FIX 3723 12702 1968 0.745464
1654616 BAD 0 1654616 3400 FIX 4221 3940 2163 0.663843 FIX 3629 12663 1988 0.749242
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2787896 BAD 0 2787896 37398 FIX -5042 8143 3127 0.798180 FIX -4743 8099 1740 0.700952
2787928 BAD -2 2787930 37399 SACC -5205 8386 3207 0.808326 FIX -4960 8379 1826 0.718066
2787964 BAD 0 2787964 37400 SACC -5265 8101 3281 0.817599 SACC -5002 8169 1886 0.729768
2787996 BAD -1 2787997 37401 SACC -5873 7817 3318 0.822196 SACC -5228 7540 1857 0.724135
2788028 BAD -2 2788030 37402 SACC -4865 6745 3413 0.833883 SACC -5321 6498 1886 0.729768
2788064 BAD 1 2788063 37403 SACC -4499 7291 3447 0.838026 SACC -4446 6902 1906 0.733627
2788096 BAD 0 2788096 37404 SACC -3981 6711 3478 0.841786 FIX -4234 6458 1923 0.736891
2788128 BAD -2 2788130 37405 FIX -3802 6366 3502 0.844686 FIX -4150 6297 1945 0.741095
2788164 BAD 1 2788163 37406 SACC -3645 6632 3580 0.854041 SACC -4049 6521 1968 0.745464
2788196 BAD 0 2788196 37407 SACC 708 5350 3460 0.839605 SACC -838 6729 2117 0.773169
2788228 BAD -2 2788230 37408 SACC 5570 5173 2710 0.743056 SACC 1853 7077 2207 0.789433
2788264 BAD 1 2788263 37409 FIX 6700 5475 2596 0.727260 FIX 1599 7377 2252 0.797440
2788296 BAD 0 2788296 37410 FIX 6675 5763 2582 0.725296 FIX 1395 7592 2276 0.801678
2788328 BAD -2 2788330 37411 FIX 6541 5857 2643 0.733813 FIX 1257 7628 2291 0.804315
2788364 BAD 1 2788363 37412 FIX 6336 5909 2700 0.741684 FIX 1023 7652 2336 0.812176
2788396 BAD 0 2788396 37413 FIX 6209 5919 2778 0.752321 FIX 895 7637 2363 0.816856
2788428 BAD -1 2788429 37414 FIX 6075 5815 2804 0.755833 FIX 794 7573 2387 0.820994
2788464 BAD 1 2788463 37415 FIX 5872 5856 2872 0.764943 FIX 740 7583 2415 0.825795
2788496 BAD -1 2788497 37416 SACC 5515 5796 2824 0.758524 FIX 852 7482 2407 0.824426
2788528 BAD -2 2788530 37417 SACC 6193 7237 1607 0.572196 SACC 1394 7941 1600 0.672162
2788564 BAD 1 2788563 37418 BLINK NaN NaN 0 0.000000 SACC 2917 8883 164 0.215197
2788596 BAD -1 2788597 37419 BLINK NaN NaN 0 0.000000 BLINK NaN NaN 0 0.000000
2788628 BAD -2 2788630 37420 NONE 4992 -2368 1793 0.604404 NONE 3001 49 1462 0.642521
2788664 GOOD 1 2788663 37421 FIX 1469 -2043 3003 0.782194 NONE 2581 -2306 2322 0.809739
2788696 GOOD 0 2788696 37422 FIX 1209 -1846 3057 0.789196 FIX 2397 -2125 2343 0.813392
2788728 GOOD -2 2788730 37423 FIX 951 -1729 3060 0.789583 FIX 2379 -1979 2363 0.816856
2788764 GOOD 1 2788763 37424 FIX 787 -1604 3077 0.791773 FIX 2336 -1832 2366 0.817375
2788796 GOOD 0 2788796 37425 FIX 640 -1492 3090 0.793444 FIX 2271 -1812 2371 0.818238
2788828 GOOD -2 2788830 37426 FIX 536 -1434 3139 0.799710 FIX 2209 -1729 2394 0.822197
2788864 GOOD 1 2788863 37427 SACC 1110 -1384 3178 0.804663 SACC 2978 -1608 2460 0.833454

34057 rows × 14 columns


In [7]:
rt_data = gaze_data['rt']
rt_data


Out[7]:
both left right target
quality frame_time_diff frame_time frame_count flag href x href y pupil area flag href x href y pupil area direction distance eccentricity x y horizontal version vertical version vergence
rep time
1 1289180 GOOD -11 NaN NaN FIX 18 -120 1057 FIX 78 -203 837 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289184 GOOD -7 NaN NaN FIX 20 -121 1056 FIX 78 -204 837 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289188 GOOD -3 NaN NaN FIX 20 -121 1055 FIX 79 -205 837 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289192 GOOD 1 1289191 95 FIX 21 -121 1054 FIX 80 -207 835 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289196 GOOD 5 NaN NaN FIX 20 -120 1054 FIX 80 -209 833 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289200 GOOD 9 NaN NaN FIX 22 -122 1052 FIX 82 -218 831 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289204 GOOD 13 NaN NaN FIX 20 -123 1051 FIX 81 -227 829 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289208 GOOD NaN NaN NaN FIX 19 -128 1050 FIX 82 -229 827 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289212 GOOD -13 NaN NaN FIX 21 -129 1049 FIX 84 -228 827 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289216 GOOD -9 NaN NaN FIX 24 -128 1049 FIX 83 -229 826 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289220 GOOD -5 NaN NaN FIX 26 -129 1050 FIX 83 -229 826 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289224 GOOD -1 1289225 96 FIX 26 -129 1050 FIX 78 -229 826 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289228 GOOD 3 NaN NaN FIX 25 -130 1049 FIX 76 -227 825 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289232 GOOD 7 NaN NaN FIX 25 -130 1046 FIX 75 -229 824 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289236 GOOD 11 NaN NaN FIX 25 -131 1045 FIX 75 -225 823 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289240 GOOD NaN NaN NaN FIX 26 -132 1045 FIX 74 -224 823 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289244 GOOD -13 NaN NaN FIX 26 -133 1044 FIX 74 -224 820 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289248 GOOD -9 NaN NaN FIX 26 -134 1044 FIX 75 -225 819 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289252 GOOD -5 NaN NaN FIX 26 -134 1042 FIX 75 -227 819 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289256 GOOD -1 1289257 97 FIX 28 -133 1041 FIX 75 -229 817 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289260 GOOD 3 NaN NaN FIX 28 -131 1041 FIX 76 -231 816 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289264 GOOD 7 NaN NaN FIX 27 -131 1041 FIX 76 -230 816 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289268 GOOD 11 NaN NaN FIX 28 -131 1038 FIX 76 -231 816 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289272 GOOD NaN NaN NaN FIX 29 -130 1038 FIX 68 -231 817 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289276 GOOD NaN NaN NaN FIX 29 -130 1038 FIX 69 -232 817 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289280 GOOD -11 NaN NaN FIX 29 -129 1038 FIX 70 -234 817 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289284 GOOD -7 NaN NaN FIX 29 -128 1036 FIX 70 -232 817 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289288 GOOD -3 NaN NaN FIX 30 -128 1035 FIX 70 -231 817 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289292 GOOD 1 1289291 98 FIX 28 -128 1034 FIX 70 -234 816 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
1289296 GOOD 5 NaN NaN FIX 29 -127 1034 FIX 69 -235 816 0 100 0 0.000000 0.000000 0.000000 0.000000 3.722915
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2 3104916 GOOD 9 NaN NaN FIX -278 4741 1324 FIX -287 4628 952 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104920 GOOD 13 NaN NaN FIX -278 4739 1323 FIX -287 4628 952 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104924 GOOD NaN NaN NaN FIX -277 4737 1322 FIX -288 4624 948 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104928 GOOD -12 NaN NaN FIX -278 4737 1322 FIX -285 4620 947 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104932 GOOD -8 NaN NaN FIX -278 4737 1322 FIX -283 4621 944 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104936 GOOD -4 NaN NaN FIX -277 4736 1321 FIX -284 4620 939 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104940 GOOD 0 3104940 41140 FIX -276 4735 1321 FIX -281 4605 939 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104944 GOOD 4 NaN NaN FIX -276 4732 1321 FIX -284 4606 939 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104948 GOOD 8 NaN NaN FIX -270 4730 1321 FIX -281 4607 940 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104952 GOOD 12 NaN NaN FIX -268 4733 1321 FIX -279 4608 951 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104956 GOOD NaN NaN NaN FIX -267 4735 1321 FIX -277 4617 951 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104960 GOOD -14 NaN NaN FIX -266 4736 1321 FIX -278 4625 951 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104964 GOOD -10 NaN NaN FIX -268 4740 1319 FIX -277 4628 950 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104968 GOOD -6 NaN NaN FIX -268 4739 1318 FIX -284 4627 949 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104972 GOOD -2 3104974 41141 FIX -269 4740 1318 FIX -286 4627 949 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104976 GOOD 2 NaN NaN FIX -269 4739 1317 FIX -286 4622 948 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104980 GOOD 6 NaN NaN FIX -266 4742 1317 FIX -290 4617 947 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104984 GOOD 10 NaN NaN FIX -267 4746 1317 FIX -292 4614 944 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104988 GOOD 14 NaN NaN FIX -265 4746 1318 FIX -294 4613 942 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104992 GOOD NaN NaN NaN FIX -264 4747 1319 FIX -289 4614 939 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3104996 GOOD -11 NaN NaN FIX -263 4747 1320 FIX -285 4608 938 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105000 GOOD -7 NaN NaN FIX -263 4744 1320 FIX -282 4606 938 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105004 GOOD -3 NaN NaN FIX -263 4744 1320 FIX -278 4608 939 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105008 GOOD 1 3105007 41142 FIX -264 4744 1321 FIX -280 4607 941 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105012 GOOD 5 NaN NaN FIX -264 4746 1321 FIX -281 4610 942 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105016 GOOD 9 NaN NaN FIX -266 4747 1322 FIX -281 4614 943 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105020 GOOD 13 NaN NaN FIX -263 4747 1322 FIX -288 4619 944 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105024 GOOD NaN NaN NaN FIX -265 4749 1322 FIX -282 4614 944 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105028 GOOD NaN NaN NaN FIX -266 4751 1321 FIX -276 4616 945 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199
3105032 GOOD NaN NaN NaN FIX -266 4747 1321 FIX -272 4617 945 270 100 16 27.563736 7.903774 -15.364554 -4.519134 3.451199

14254 rows × 20 columns


In [37]:
rt_data.reset_index(inplace=True)

In [38]:
rt_data.set_index(['rep', ('target', 'distance'), ('target', 'eccentricity'), ('target', 'direction'), 'time'], inplace=True)
rt_data.sortlevel(axis=0, inplace=True)

In [39]:
rt_data


Out[39]:
both left right target both
quality flag href x href y pupil area flag href x href y pupil area x y horizontal version vertical version vergence frame_time_diff frame_time frame_count
rep (target, distance) (target, eccentricity) (target, direction) time
1 50 0 0 1426620 GOOD FIX 257 -98 1324 FIX -514 -100 1003 0.00000 0.000000 0.000000 0.000000 7.437988 -14 NaN NaN
1426624 GOOD FIX 259 -97 1324 FIX -514 -94 1000 0.00000 0.000000 0.000000 0.000000 7.437988 -10 NaN NaN
1426628 GOOD FIX 259 -94 1320 FIX -514 -93 1000 0.00000 0.000000 0.000000 0.000000 7.437988 -6 NaN NaN
1426632 GOOD FIX 258 -92 1319 FIX -515 -92 996 0.00000 0.000000 0.000000 0.000000 7.437988 -2 1426634 1580
1426636 GOOD FIX 258 -91 1318 FIX -514 -89 996 0.00000 0.000000 0.000000 0.000000 7.437988 2 NaN NaN
1426640 GOOD FIX 259 -88 1318 FIX -514 -86 997 0.00000 0.000000 0.000000 0.000000 7.437988 6 NaN NaN
1426644 GOOD FIX 260 -88 1318 FIX -512 -83 1004 0.00000 0.000000 0.000000 0.000000 7.437988 10 NaN NaN
1426648 GOOD FIX 260 -89 1318 FIX -510 -79 1004 0.00000 0.000000 0.000000 0.000000 7.437988 14 NaN NaN
1426652 GOOD FIX 259 -88 1316 FIX -506 -75 1004 0.00000 0.000000 0.000000 0.000000 7.437988 NaN NaN NaN
1426656 GOOD FIX 258 -88 1315 FIX -505 -78 1004 0.00000 0.000000 0.000000 0.000000 7.437988 -11 NaN NaN
1426660 GOOD FIX 260 -88 1314 FIX -505 -81 1004 0.00000 0.000000 0.000000 0.000000 7.437988 -7 NaN NaN
1426664 GOOD FIX 259 -86 1312 FIX -510 -77 1001 0.00000 0.000000 0.000000 0.000000 7.437988 -3 NaN NaN
1426668 GOOD FIX 258 -76 1309 FIX -512 -78 999 0.00000 0.000000 0.000000 0.000000 7.437988 1 1426667 1581
1426672 GOOD FIX 261 -73 1309 FIX -514 -78 996 0.00000 0.000000 0.000000 0.000000 7.437988 5 NaN NaN
1426676 GOOD FIX 262 -74 1311 FIX -514 -78 992 0.00000 0.000000 0.000000 0.000000 7.437988 9 NaN NaN
1426680 GOOD FIX 263 -74 1311 FIX -514 -78 991 0.00000 0.000000 0.000000 0.000000 7.437988 13 NaN NaN
1426684 GOOD FIX 265 -75 1304 FIX -516 -75 990 0.00000 0.000000 0.000000 0.000000 7.437988 NaN NaN NaN
1426688 GOOD FIX 267 -73 1302 FIX -515 -77 990 0.00000 0.000000 0.000000 0.000000 7.437988 -13 NaN NaN
1426692 GOOD FIX 270 -71 1301 FIX -516 -79 990 0.00000 0.000000 0.000000 0.000000 7.437988 -9 NaN NaN
1426696 GOOD FIX 271 -69 1300 FIX -515 -81 990 0.00000 0.000000 0.000000 0.000000 7.437988 -5 NaN NaN
1426700 GOOD FIX 268 -68 1299 FIX -514 -80 991 0.00000 0.000000 0.000000 0.000000 7.437988 -1 1426701 1582
1426704 GOOD FIX 265 -67 1299 FIX -518 -80 991 0.00000 0.000000 0.000000 0.000000 7.437988 3 NaN NaN
1426708 GOOD FIX 264 -68 1298 FIX -522 -74 992 0.00000 0.000000 0.000000 0.000000 7.437988 7 NaN NaN
1426712 GOOD FIX 262 -68 1297 FIX -522 -66 992 0.00000 0.000000 0.000000 0.000000 7.437988 11 NaN NaN
1426716 GOOD FIX 270 -68 1295 FIX -523 -70 989 0.00000 0.000000 0.000000 0.000000 7.437988 NaN NaN NaN
1426720 GOOD FIX 270 -65 1294 FIX -522 -62 987 0.00000 0.000000 0.000000 0.000000 7.437988 -14 NaN NaN
1426724 GOOD FIX 268 -64 1294 FIX -520 -59 985 0.00000 0.000000 0.000000 0.000000 7.437988 -10 NaN NaN
1426728 GOOD FIX 267 -63 1294 FIX -517 -57 981 0.00000 0.000000 0.000000 0.000000 7.437988 -6 NaN NaN
1426732 GOOD FIX 267 -59 1290 FIX -516 -56 981 0.00000 0.000000 0.000000 0.000000 7.437988 -2 1426734 1583
1426736 GOOD FIX 267 -56 1288 FIX -517 -58 981 0.00000 0.000000 0.000000 0.000000 7.437988 2 NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2 450 3 270 2806912 GOOD FIX -734 679 2088 FIX 372 423 1540 23.55118 1.234265 -2.995885 -0.157151 0.825328 -8 NaN NaN
2806916 GOOD FIX -733 678 2089 FIX 370 421 1545 23.55118 1.234265 -2.995885 -0.157151 0.825328 -4 NaN NaN
2806920 GOOD FIX -733 677 2096 FIX 370 412 1546 23.55118 1.234265 -2.995885 -0.157151 0.825328 0 2806920 37810
2806924 GOOD FIX -732 676 2097 FIX 369 411 1547 23.55118 1.234265 -2.995885 -0.157151 0.825328 4 NaN NaN
2806928 GOOD FIX -732 676 2098 FIX 368 410 1547 23.55118 1.234265 -2.995885 -0.157151 0.825328 8 NaN NaN
2806932 GOOD FIX -732 676 2099 FIX 368 402 1547 23.55118 1.234265 -2.995885 -0.157151 0.825328 12 NaN NaN
2806936 GOOD FIX -730 676 2100 FIX 368 402 1547 23.55118 1.234265 -2.995885 -0.157151 0.825328 NaN NaN NaN
2806940 GOOD FIX -730 675 2103 FIX 363 401 1548 23.55118 1.234265 -2.995885 -0.157151 0.825328 -13 NaN NaN
2806944 GOOD FIX -729 673 2107 FIX 363 400 1549 23.55118 1.234265 -2.995885 -0.157151 0.825328 -9 NaN NaN
2806948 GOOD FIX -728 672 2111 FIX 362 400 1556 23.55118 1.234265 -2.995885 -0.157151 0.825328 -5 NaN NaN
2806952 GOOD FIX -726 667 2111 FIX 361 399 1557 23.55118 1.234265 -2.995885 -0.157151 0.825328 -1 2806953 37811
2806956 GOOD FIX -729 663 2112 FIX 362 400 1559 23.55118 1.234265 -2.995885 -0.157151 0.825328 3 NaN NaN
2806960 GOOD FIX -729 662 2114 FIX 362 394 1559 23.55118 1.234265 -2.995885 -0.157151 0.825328 7 NaN NaN
2806964 GOOD FIX -730 661 2116 FIX 362 392 1560 23.55118 1.234265 -2.995885 -0.157151 0.825328 11 NaN NaN
2806968 GOOD FIX -729 661 2116 FIX 361 390 1562 23.55118 1.234265 -2.995885 -0.157151 0.825328 NaN NaN NaN
2806972 GOOD FIX -729 657 2116 FIX 360 388 1564 23.55118 1.234265 -2.995885 -0.157151 0.825328 NaN NaN NaN
2806976 GOOD FIX -729 657 2116 FIX 359 389 1565 23.55118 1.234265 -2.995885 -0.157151 0.825328 -11 NaN NaN
2806980 GOOD FIX -731 658 2117 FIX 348 384 1566 23.55118 1.234265 -2.995885 -0.157151 0.825328 -7 NaN NaN
2806984 GOOD FIX -731 657 2119 FIX 351 383 1567 23.55118 1.234265 -2.995885 -0.157151 0.825328 -3 NaN NaN
2806988 GOOD FIX -730 657 2123 FIX 349 377 1568 23.55118 1.234265 -2.995885 -0.157151 0.825328 1 2806987 37812
2806992 GOOD FIX -730 657 2123 FIX 353 375 1570 23.55118 1.234265 -2.995885 -0.157151 0.825328 5 NaN NaN
2806996 GOOD FIX -728 657 2126 FIX 357 372 1573 23.55118 1.234265 -2.995885 -0.157151 0.825328 9 NaN NaN
2807000 GOOD FIX -729 658 2129 FIX 353 369 1574 23.55118 1.234265 -2.995885 -0.157151 0.825328 13 NaN NaN
2807004 GOOD FIX -730 659 2132 FIX 349 366 1575 23.55118 1.234265 -2.995885 -0.157151 0.825328 NaN NaN NaN
2807008 GOOD FIX -731 659 2135 FIX 349 356 1578 23.55118 1.234265 -2.995885 -0.157151 0.825328 -12 NaN NaN
2807012 GOOD FIX -731 660 2136 FIX 350 361 1581 23.55118 1.234265 -2.995885 -0.157151 0.825328 -8 NaN NaN
2807016 GOOD FIX -732 661 2141 FIX 351 359 1583 23.55118 1.234265 -2.995885 -0.157151 0.825328 -4 NaN NaN
2807020 GOOD FIX -732 665 2141 FIX 352 363 1583 23.55118 1.234265 -2.995885 -0.157151 0.825328 0 2807020 37813
2807024 GOOD FIX -734 669 2141 FIX 353 367 1584 23.55118 1.234265 -2.995885 -0.157151 0.825328 4 NaN NaN
2807028 GOOD FIX -736 671 2143 FIX 354 360 1585 23.55118 1.234265 -2.995885 -0.157151 0.825328 8 NaN NaN

14254 rows × 17 columns


In [40]:
rt_data.loc[(1, 100, 0, 0)]


Out[40]:
both left right target both
quality flag href x href y pupil area flag href x href y pupil area x y horizontal version vertical version vergence frame_time_diff frame_time frame_count
time
1289180 GOOD FIX 18 -120 1057 FIX 78 -203 837 0 0 0 0 3.722915 -11 NaN NaN
1289184 GOOD FIX 20 -121 1056 FIX 78 -204 837 0 0 0 0 3.722915 -7 NaN NaN
1289188 GOOD FIX 20 -121 1055 FIX 79 -205 837 0 0 0 0 3.722915 -3 NaN NaN
1289192 GOOD FIX 21 -121 1054 FIX 80 -207 835 0 0 0 0 3.722915 1 1289191 95
1289196 GOOD FIX 20 -120 1054 FIX 80 -209 833 0 0 0 0 3.722915 5 NaN NaN
1289200 GOOD FIX 22 -122 1052 FIX 82 -218 831 0 0 0 0 3.722915 9 NaN NaN
1289204 GOOD FIX 20 -123 1051 FIX 81 -227 829 0 0 0 0 3.722915 13 NaN NaN
1289208 GOOD FIX 19 -128 1050 FIX 82 -229 827 0 0 0 0 3.722915 NaN NaN NaN
1289212 GOOD FIX 21 -129 1049 FIX 84 -228 827 0 0 0 0 3.722915 -13 NaN NaN
1289216 GOOD FIX 24 -128 1049 FIX 83 -229 826 0 0 0 0 3.722915 -9 NaN NaN
1289220 GOOD FIX 26 -129 1050 FIX 83 -229 826 0 0 0 0 3.722915 -5 NaN NaN
1289224 GOOD FIX 26 -129 1050 FIX 78 -229 826 0 0 0 0 3.722915 -1 1289225 96
1289228 GOOD FIX 25 -130 1049 FIX 76 -227 825 0 0 0 0 3.722915 3 NaN NaN
1289232 GOOD FIX 25 -130 1046 FIX 75 -229 824 0 0 0 0 3.722915 7 NaN NaN
1289236 GOOD FIX 25 -131 1045 FIX 75 -225 823 0 0 0 0 3.722915 11 NaN NaN
1289240 GOOD FIX 26 -132 1045 FIX 74 -224 823 0 0 0 0 3.722915 NaN NaN NaN
1289244 GOOD FIX 26 -133 1044 FIX 74 -224 820 0 0 0 0 3.722915 -13 NaN NaN
1289248 GOOD FIX 26 -134 1044 FIX 75 -225 819 0 0 0 0 3.722915 -9 NaN NaN
1289252 GOOD FIX 26 -134 1042 FIX 75 -227 819 0 0 0 0 3.722915 -5 NaN NaN
1289256 GOOD FIX 28 -133 1041 FIX 75 -229 817 0 0 0 0 3.722915 -1 1289257 97
1289260 GOOD FIX 28 -131 1041 FIX 76 -231 816 0 0 0 0 3.722915 3 NaN NaN
1289264 GOOD FIX 27 -131 1041 FIX 76 -230 816 0 0 0 0 3.722915 7 NaN NaN
1289268 GOOD FIX 28 -131 1038 FIX 76 -231 816 0 0 0 0 3.722915 11 NaN NaN
1289272 GOOD FIX 29 -130 1038 FIX 68 -231 817 0 0 0 0 3.722915 NaN NaN NaN
1289276 GOOD FIX 29 -130 1038 FIX 69 -232 817 0 0 0 0 3.722915 NaN NaN NaN
1289280 GOOD FIX 29 -129 1038 FIX 70 -234 817 0 0 0 0 3.722915 -11 NaN NaN
1289284 GOOD FIX 29 -128 1036 FIX 70 -232 817 0 0 0 0 3.722915 -7 NaN NaN
1289288 GOOD FIX 30 -128 1035 FIX 70 -231 817 0 0 0 0 3.722915 -3 NaN NaN
1289292 GOOD FIX 28 -128 1034 FIX 70 -234 816 0 0 0 0 3.722915 1 1289291 98
1289296 GOOD FIX 29 -127 1034 FIX 69 -235 816 0 0 0 0 3.722915 5 NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1289560 GOOD FIX 36 -115 1013 FIX 32 -227 803 0 0 0 0 3.722915 2 NaN NaN
1289564 GOOD FIX 41 -115 1014 FIX 32 -225 803 0 0 0 0 3.722915 6 NaN NaN
1289568 GOOD FIX 42 -117 1014 FIX 32 -229 803 0 0 0 0 3.722915 10 NaN NaN
1289572 GOOD FIX 43 -119 1015 FIX 31 -234 804 0 0 0 0 3.722915 14 NaN NaN
1289576 GOOD FIX 43 -120 1016 FIX 34 -234 807 0 0 0 0 3.722915 NaN NaN NaN
1289580 GOOD FIX 43 -121 1017 FIX 36 -234 808 0 0 0 0 3.722915 -11 NaN NaN
1289584 GOOD FIX 44 -122 1018 FIX 38 -237 808 0 0 0 0 3.722915 -7 NaN NaN
1289588 GOOD FIX 44 -122 1019 FIX 38 -234 808 0 0 0 0 3.722915 -3 NaN NaN
1289592 GOOD FIX 49 -122 1020 FIX 37 -235 808 0 0 0 0 3.722915 1 1289591 107
1289596 GOOD FIX 49 -124 1022 FIX 35 -237 808 0 0 0 0 3.722915 5 NaN NaN
1289600 GOOD FIX 48 -123 1024 FIX 33 -237 808 0 0 0 0 3.722915 9 NaN NaN
1289604 GOOD FIX 51 -125 1024 FIX 31 -240 808 0 0 0 0 3.722915 13 NaN NaN
1289608 GOOD FIX 52 -126 1024 FIX 33 -235 808 0 0 0 0 3.722915 NaN NaN NaN
1289612 GOOD FIX 53 -128 1025 FIX 35 -233 809 0 0 0 0 3.722915 -12 NaN NaN
1289616 GOOD FIX 57 -129 1028 FIX 37 -232 812 0 0 0 0 3.722915 -8 NaN NaN
1289620 GOOD FIX 59 -133 1029 FIX 39 -237 814 0 0 0 0 3.722915 -4 NaN NaN
1289624 GOOD FIX 61 -132 1030 FIX 41 -239 818 0 0 0 0 3.722915 0 1289624 108
1289628 GOOD FIX 65 -133 1032 FIX 43 -240 818 0 0 0 0 3.722915 4 NaN NaN
1289632 GOOD FIX 63 -133 1032 FIX 44 -241 819 0 0 0 0 3.722915 8 NaN NaN
1289636 GOOD FIX 65 -134 1032 FIX 45 -247 819 0 0 0 0 3.722915 12 NaN NaN
1289640 GOOD FIX 67 -134 1032 FIX 45 -242 818 0 0 0 0 3.722915 NaN NaN NaN
1289644 GOOD FIX 65 -138 1034 FIX 45 -243 819 0 0 0 0 3.722915 NaN NaN NaN
1289648 GOOD FIX 65 -143 1034 FIX 45 -244 819 0 0 0 0 3.722915 -11 NaN NaN
1289652 GOOD FIX 65 -143 1035 FIX 40 -246 819 0 0 0 0 3.722915 -7 NaN NaN
1289656 GOOD FIX 58 -143 1037 FIX 35 -247 820 0 0 0 0 3.722915 -3 NaN NaN
1289660 GOOD FIX 57 -144 1038 FIX 25 -253 822 0 0 0 0 3.722915 1 1289659 109
1289664 GOOD FIX 55 -146 1038 FIX 18 -255 822 0 0 0 0 3.722915 5 NaN NaN
1289668 GOOD FIX 52 -147 1038 FIX 11 -258 823 0 0 0 0 3.722915 9 NaN NaN
1289672 GOOD FIX 52 -149 1038 FIX 11 -260 824 0 0 0 0 3.722915 13 NaN NaN
1289676 GOOD FIX 53 -154 1038 FIX 10 -261 825 0 0 0 0 3.722915 NaN NaN NaN

125 rows × 17 columns


In [112]:
HREF_DIST = 15000.0
calibration_dist = 100.

def _find_href_center(rt_df):


    central_target = (rt_df['target', 'direction'] == 0) & \
                     (rt_df['target', 'eccentricity'] == 0) & \
                     (rt_df['target', 'distance'] == calibration_dist)

    good_data = rt_df['both', 'quality'] == 'GOOD'

    central_data = rt_df[[('left', 'href x'), ('left', 'href y'),
                          ('right', 'href x'), ('right', 'href y')]][central_target & good_data]

    return central_data.loc[1].median()

def convert_href_to_bref(df, rt_df):

    CM_PER_HREF_UNIT = calibration_dist / HREF_DIST

    center = _find_href_center(rt_df)

    for eye in ['left', 'right']:
        df[eye, 'bref x'] = (df[eye, 'href x'] - center[eye, 'href x']) * CM_PER_HREF_UNIT
        df[eye, 'bref y'] = (df[eye, 'href y'] - center[eye, 'href y']) * CM_PER_HREF_UNIT
        df[eye, 'bref z'] = calibration_dist

convert_href_to_bref(task_df, rt_data.copy())
task_df.sortlevel(axis=1, inplace=True)

In [113]:
def fit_plane(fix_L, fix_R, ipd, check_results=False, plot_results=False):
    """
    The data from the Eyelink rarely results in gaze directions for the two eyes that actually
    intersection. The goal of this function is to take the skew gaze rays for a given time point
    and force them lie in a common epipolar plane. To do this, we find the equation of a plane 
    that contains the optical centers of the left and right eyes (loc_L and loc_R), 
    and has the minimum least squares distance from the fixation points (or probably more accurately 
    gaze directions, since theyre monocular) of the two eyes (fix_L and fix_R). All vectors are expected
    to be 3X1

    The functional optionally checks to make sure the resulting elevation angles are the same
    for each eye, and generates at plot of the original and new gaze vectors.
    """


    # ADJUST fix_L AND fix_R to still lie along gaze direction, but each be unit
    # length from eye locations loc_L and p2
    loc_L = np.array([[-ipd/2., 0, 0]]).T
    loc_R = np.array([[ipd/2., 0, 0]]).T
    
    assert fix_L.shape == (3,1)
    assert fix_R.shape == (3,1)

    fix_L = fix_L - loc_L                       # translate fix_L into coordinate system with loc_L at origin
    fix_L = fix_L / np.linalg.norm(fix_L)       # make unit length
    fix_L = fix_L + loc_L                       # translate back in to cyclopean coordinates

    fix_R = fix_R - loc_R                       # translate fix_R into coordinate system with loc_R at origin
    fix_R = fix_R / np.linalg.norm(fix_R)       # make unit length
    fix_R = fix_R + loc_R                       # translate back in to cyclopean coordinates

    # SOLVE FOR PLANE THROUGH loc_L AND loc_R, WHILE MINIMIZING DISTANCE TO fix_L AND fix_R: 
    # CONSTRAINED LEAST-SQUARES (solve: y = bz)
    # the only degree of freedom is the rotation of the plane around the x axis that runs between loc_L and loc_R
    # so we find the linear least squares solution for y = bz
    # http://en.wikipedia.org/wiki/Linear_least_squares_(mathematics)

    y = np.matrix([[loc_L[1,0], fix_L[1,0], loc_R[1,0], fix_R[1,0]]]).T # y column vector
    Z = np.matrix([[loc_L[2,0], fix_L[2,0], loc_R[2,0], fix_R[2,0]]]).T # Z column vector

    b = np.linalg.inv(Z.T * Z) * Z.T * y    # least squares solution for b


    # PROJECT VECTORS ONTO PLANE to get new point coordinates
    fix_L_new  = np.array([[fix_L[0,0], b*fix_L[2,0], fix_L[2,0]]]).T # project (x and z are the same, y = bz)
    fix_R_new  = np.array([[fix_R[0,0], b*fix_R[2,0], fix_R[2,0]]]).T # project


    if check_results:
        
        # check that elevation angles are the same
        P = np.array([0, -1, b])    # vector normal to the epipolar plane
        P = P / np.linalg.norm(P)               # normalize

        # angle between original vectors and epipolar plane
        th_L = np.degrees(np.arcsin(np.dot( P, fix_L / np.linalg.norm(fix_L))))
        th_R = np.degrees(np.arcsin(np.dot( P, fix_R / np.linalg.norm(fix_R ))))
        
        th_L_new = np.degrees(np.arcsin(np.dot( P, (fix_L_new) / np.linalg.norm(fix_L_new))))
        th_R_new = np.degrees(np.arcsin(np.dot( P, (fix_R_new) / np.linalg.norm(fix_R_new))))

#         print "Align Eyes Adjustment (L/R in deg)", th_L, th_R
        if np.absolute(th_L_new) > 1e-10 or np.absolute(th_R_new) > 1e-10:
            raise ValueError("Projection to epipolar plane failed")

    if plot_results:
        #points for epipolar plane
        [xramp,zramp]   = np.meshgrid( np.linspace(-1.5,1.5, 5), np.linspace(-0.1,1.1, 5) );
        yramp           = zramp.copy()
        yramp           = b[0,0]*yramp

        fig = plt.figure()
        ax = plt.subplot(111,projection='3d')

        # # epipolar plane
        ax.plot_wireframe( xramp, zramp, yramp);

        #cyclopean eye and interocular axis
        ax.plot( [0.], [0.], [0.],'ko', zdir='y')
        ax.plot( [loc_R[0,0],loc_L[0,0]], [loc_R[1,0],loc_L[1,0]], [loc_R[2,0],loc_L[2,0]],'c', zdir='y')
        # original gaze vectors
        ax.plot( [loc_L[0,0],fix_L[0,0]], [loc_L[1.0],fix_L[1,0]], [loc_L[2,0],fix_L[2,0]],'k-o', zdir='y')
        ax.plot( [loc_R[0,0],fix_R[0,0]], [loc_R[1,0],fix_R[1,0]], [loc_R[2,0],fix_R[2,0]],'k-o', zdir='y')
        # new gaze vectors
        ax.plot( [loc_L[0,0],fix_L_new[0,0]], [loc_L[1,0],fix_L_new[1,0]], [loc_L[2,0],fix_L_new[2,0]],'g-o', zdir='y')
        ax.plot( [loc_R[0,0],fix_R_new[0,0]], [loc_R[1,0],fix_R_new[1,0]], [loc_R[2,0],fix_R_new[2,0]],'r-o', zdir='y')
        
        ax.set_xlabel('X')
        ax.set_ylabel('Z')
        ax.set_zlabel('Y')
        
        ax.set_zlim3d(.1, -.1)  # Adjust the vertical limits
        ax.set_ylim3d(-.1, 1.1)  # Adjust the depth limits


    return fix_L_new, fix_R_new

In [114]:
def align_eyes(gaze_df, ipd):

    df = gaze_df.loc[:, (['left', 'right'], ['bref x', 'bref y', 'bref z'])].copy()
    fix_L = []
    fix_R = []
    idxs = []

    for idx, row in df.iterrows():
        new_fix_L, new_fix_R = fit_plane(np.atleast_2d(row['left'].values).T,
                                         np.atleast_2d(row['right'].values).T,
                                         ipd, check_results=True)

        fix_L.append(new_fix_L.squeeze())
        fix_R.append(new_fix_R.squeeze())
        idxs.append(idx)

    midx = pd.MultiIndex.from_tuples(idxs, names=['rep', 'time'])
    cols = ['bref x', 'bref y', 'bref z']
    fix_L = pd.DataFrame(np.array(fix_L), index=midx, columns=pd.MultiIndex.from_product([['left'], cols]))
    fix_R = pd.DataFrame(np.array(fix_R), index=midx, columns=pd.MultiIndex.from_product([['right'], cols]))
    
    gaze_df.loc[:, ('left',['bref x', 'bref y', 'bref z'])] = fix_L
    gaze_df.loc[:, ('right',['bref x', 'bref y', 'bref z'])] = fix_R

In [115]:
align_eyes(task_df, subject.ipd)

In [116]:
v = task_df.loc[:, (['left', 'right'],['bref x', 'bref y', 'bref z'])].copy()
v


Out[116]:
left right
bref x bref y bref z bref x bref y bref z
rep time
1 1653668 -3.349928 0.004606 0.994971 3.147982 0.004605 0.994652
1653684 -3.350914 0.007291 0.994882 3.146808 0.007288 0.994466
1653716 -3.354918 0.012030 0.994481 3.145244 0.012026 0.994202
1653748 -3.357602 0.019642 0.994168 3.140356 0.019628 0.993452
1653784 -3.364724 0.024167 0.993280 3.136501 0.024160 0.992989
1653816 -3.369223 0.030304 0.992699 3.132494 0.030288 0.992169
1653848 -3.379818 0.036407 0.991231 3.124126 0.036394 0.990877
1653884 -3.383231 0.044407 0.990565 3.123273 0.044396 0.990315
1653916 -3.386240 0.053615 0.989879 3.123358 0.053603 0.989650
1653948 -3.377618 0.063082 0.990569 3.125515 0.063001 0.989288
1653976 -3.356643 0.062649 0.993256 3.149995 0.062556 0.991787
1657048 NaN NaN NaN 3.449582 NaN 0.972146
1657076 NaN NaN NaN 3.443996 NaN 0.978294
1657284 -3.204599 0.586202 0.817054 3.246369 0.578981 0.806989
1660248 -3.385068 0.052630 0.989994 3.101741 0.052463 0.986858
1660284 -3.392334 0.051602 0.989117 3.103945 0.051496 0.987081
1660316 -3.394102 0.058135 0.988583 3.104459 0.058025 0.986717
1660348 -3.469193 0.093511 0.972032 3.010096 0.092874 0.965408
1660384 -3.479176 0.122052 0.966580 2.995988 0.121052 0.958658
1660416 -3.480659 0.123858 0.966043 2.999289 0.122985 0.959232
1660448 -3.483829 0.123324 0.965306 3.000463 0.122599 0.959634
1660484 -3.485868 0.126699 0.964695 2.999100 0.125884 0.958487
1660516 -3.475908 0.136615 0.965830 3.001239 0.135455 0.957633
1660784 -3.290523 -0.039603 0.997284 3.243435 -0.039704 0.999819
1660816 -3.281832 -0.034481 0.997873 3.245567 -0.034551 0.999916
1660848 -3.288735 -0.034449 0.997464 3.247300 -0.034535 0.999953
1660884 -3.294052 -0.033520 0.997406 3.247167 -0.033605 0.999943
1660916 -3.297369 -0.034010 0.997240 3.248033 -0.034102 0.999938
1660948 -3.300944 -0.034121 0.996956 3.249767 -0.034224 0.999956
1660984 -3.369811 0.007299 0.992637 3.184939 0.007333 0.997358
... ... ... ... ... ... ...
2786996 -3.345839 -0.022103 0.995215 3.196129 -0.022170 0.998229
2787028 -3.341234 -0.022643 0.995637 3.202237 -0.022709 0.998526
2787064 -3.337810 -0.043592 0.995206 3.206916 -0.043718 0.998091
2787096 -3.333300 -0.054413 0.995221 3.208473 -0.054535 0.997453
2787128 -3.326837 -0.054705 0.995726 3.214250 -0.054812 0.997661
2787164 -3.321294 -0.055662 0.996191 3.217844 -0.055741 0.997608
2787196 -3.317661 -0.054780 0.996487 3.219769 -0.054848 0.997725
2787228 -3.313819 -0.056383 0.996646 3.224557 -0.056447 0.997777
2787264 -3.303797 -0.064200 0.996850 3.234208 -0.064237 0.997411
2787296 -3.302275 -0.063610 0.996976 3.234739 -0.063640 0.997447
2787328 -3.301544 -0.065039 0.996991 3.234476 -0.065057 0.997269
2787364 -3.300423 -0.064583 0.997158 3.235275 -0.064586 0.997209
2787396 -3.299029 -0.064818 0.997198 3.236006 -0.064820 0.997224
2787428 -3.302561 -0.057484 0.997365 3.232739 -0.057506 0.997737
2787464 -3.328463 0.058036 0.994456 3.202140 0.058230 0.997781
2787496 -3.320712 0.075470 0.993616 3.211340 0.075745 0.997242
2787528 -3.321434 0.064995 0.994440 3.210254 0.065215 0.997809
2787564 -3.324404 0.053106 0.995145 3.206712 0.053268 0.998180
2787596 -3.326681 0.047090 0.995432 3.203583 0.047222 0.998219
2787628 -3.326779 0.040109 0.995837 3.203374 0.040213 0.998424
2787664 -3.440841 0.162712 0.966285 3.100606 0.164456 0.976642
2787696 -3.468119 0.333212 0.910979 3.026497 0.336749 0.920650
2787728 -3.465334 0.440462 0.852134 2.952672 0.445771 0.862405
2788664 -3.124015 -0.130894 0.984004 3.383355 -0.130595 0.981755
2788696 -3.140682 -0.118914 0.987513 3.371686 -0.118585 0.984782
2788728 -3.157431 -0.110537 0.990048 3.370660 -0.110091 0.986052
2788764 -3.168109 -0.101744 0.991819 3.367998 -0.101294 0.987433
2788796 -3.177724 -0.097502 0.993257 3.363791 -0.096991 0.988059
2788828 -3.184557 -0.092915 0.994067 3.359818 -0.092446 0.989058
2788864 -3.146820 -0.086994 0.991166 3.409554 -0.086284 0.983080

18419 rows × 6 columns


In [117]:
def calc_fixation_pts(df, ipd):
# ipd = subject.ipd

    gaze_data = task_df.loc[:,(['left', 'right'], ['bref x', 'bref y', 'bref z'])]

    L = np.array([-ipd/2., 0, 0])
    R = np.array([ipd/2., 0, 0])

    left_data = gaze_data['left'].values - L
    right_data = gaze_data['right'].values - R

    s = (np.sqrt(np.sum(np.cross(R-L, right_data)**2, axis=1))) / \
        (np.sqrt(np.sum(np.cross(left_data, right_data)**2, axis=1)))

    fixation_pt = np.expand_dims(s, axis=1)*left_data
    
    cols = ['fixation x', 'fixation y', 'fixation z']
    fix_df = pd.DataFrame(fixation_pt, index=df.index, columns=cols)
    
    for col in cols:
        df['both', col] = fix_df[col]
        
    df.sortlevel(axis=1, inplace=True)

In [118]:
calc_fixation_pts(task_df, subject.ipd)

In [119]:
task_df


Out[119]:
both left right
quality frame_time_diff frame_time frame_count fixation x fixation y fixation z flag href x href y ... bref x bref y bref z flag href x href y pupil area bref x bref y bref z
rep time
1 1653668 GOOD 1 1653667 3371 -306.007813 14.105897 3046.875000 FIX -1958 -227 ... -3.349928 0.004606 0.994971 FIX -995 8 1403 3.147982 0.004605 0.994652
1653684 GOOD 1 1653683 3372 -282.564286 20.414063 2785.714286 FIX -1973 -200 ... -3.350914 0.007291 0.994882 FIX -1013 62 1416 3.146808 0.007288 0.994466
1653716 GOOD 0 1653716 3373 -5143.125000 589.706864 48750.000000 FIX -2034 -126 ... -3.354918 0.012030 0.994481 FIX -1037 131 1431 3.145244 0.012026 0.994202
1653748 GOOD -1 1653749 3374 -329.773438 60.198957 3046.875000 FIX -2075 -15 ... -3.357602 0.019642 0.994168 FIX -1112 250 1442 3.140356 0.019628 0.993452
1653784 GOOD 1 1653783 3375 -625.625000 131.791387 5416.666667 FIX -2184 108 ... -3.364724 0.024167 0.993280 FIX -1171 264 1449 3.136501 0.024160 0.992989
1653816 GOOD 0 1653816 3376 -468.390000 119.054732 3900.000000 FIX -2253 153 ... -3.369223 0.030304 0.992699 FIX -1233 405 1459 3.132494 0.030288 0.992169
1653848 GOOD -2 1653850 3377 -216.427966 60.696371 1652.542373 FIX -2416 250 ... -3.379818 0.036407 0.991231 FIX -1362 494 1461 3.124126 0.036394 0.990877
1653884 GOOD 1 1653883 3378 -133.813776 44.601468 994.897959 FIX -2469 363 ... -3.383231 0.044407 0.990565 FIX -1376 624 1469 3.123273 0.044396 0.990315
1653916 GOOD 0 1653916 3379 -92.546552 36.420227 672.413793 FIX -2516 479 ... -3.386240 0.053615 0.989879 FIX -1376 788 1473 3.123358 0.053603 0.989650
1653948 GOOD -2 1653950 3380 -279.138889 137.979178 2166.666667 SACC -2384 632 ... -3.377618 0.063082 0.990569 FIX -1344 921 1485 3.125515 0.063001 0.989288
1653976 GOOD -7 1653983 3381 -106.818878 62.752575 994.897959 SACC -2062 564 ... -3.356643 0.062649 0.993256 SACC -969 971 1479 3.149995 0.062556 0.991787
1657048 GOOD -1 1657049 3473 NaN NaN NaN BLINK NaN NaN ... NaN NaN NaN SACC 3623 -2131 1191 3.449582 NaN 0.972146
1657076 GOOD -7 1657083 3474 NaN NaN NaN BLINK NaN NaN ... NaN NaN NaN SACC 3518 -1352 1550 3.443996 NaN 0.978294
1657284 GOOD 1 1657283 3480 6.013041 77.638324 108.213097 NONE 382 10429 ... -3.204599 0.586202 0.817054 FIX 476 10742 1606 3.246369 0.578981 0.806989
1660248 GOOD -2 1660250 3569 -64.262077 25.040137 471.014493 FIX -2498 496 ... -3.385068 0.052630 0.989994 FIX -1710 742 2263 3.101741 0.052463 0.986858
1660284 GOOD 1 1660283 3570 -230.004098 83.386555 1598.360656 FIX -2610 442 ... -3.392334 0.051602 0.989117 FIX -1676 766 2259 3.103945 0.051496 0.987081
1660316 GOOD 0 1660316 3571 -546.625000 220.523689 3750.000000 FIX -2638 545 ... -3.394102 0.058135 0.988583 FIX -1669 862 2265 3.104459 0.058025 0.986717
1660348 GOOD -2 1660350 3572 -63.728261 27.187375 282.608696 SACC -3834 1178 ... -3.469193 0.093511 0.972032 SACC -3184 1352 2186 3.010096 0.092874 0.965408
1660384 GOOD 1 1660383 3573 -55.304426 29.453370 233.253589 FIX -4008 1660 ... -3.479176 0.122052 0.966580 FIX -3431 1772 2159 2.995988 0.121052 0.958658
1660416 GOOD 0 1660416 3574 -68.671829 36.875119 287.610619 FIX -4033 1685 ... -3.480659 0.123858 0.966043 FIX -3377 1805 2181 2.999289 0.122985 0.959232
1660448 GOOD -1 1660449 3575 -88.455993 46.652615 365.168539 FIX -4085 1683 ... -3.483829 0.123324 0.965306 FIX -3357 1793 2160 3.000463 0.122599 0.959634
1660484 GOOD 1 1660483 3576 -92.041506 49.441113 376.447876 FIX -4119 1699 ... -3.485868 0.126699 0.964695 FIX -3383 1885 2188 2.999100 0.125884 0.958487
1660516 GOOD 0 1660516 3577 -58.776418 35.544304 251.288660 FIX -3960 1850 ... -3.475908 0.136615 0.965830 SACC -3353 2038 2236 3.001239 0.135455 0.957633
1660784 GOOD 0 1660784 3585 -7.752935 -7.576967 190.802348 FIX -1061 -1048 ... -3.290523 -0.039603 0.997284 FIX 445 -503 2159 3.243435 -0.039704 0.999819
1660816 GOOD 0 1660816 3586 -7.549150 -8.177269 236.650485 FIX -930 -978 ... -3.281832 -0.034481 0.997873 FIX 477 -418 2163 3.245567 -0.034551 0.999916
1660848 GOOD -1 1660849 3587 -6.985701 -6.212841 179.889299 FIX -1034 -1021 ... -3.288735 -0.034449 0.997464 FIX 503 -375 2176 3.247300 -0.034535 0.999953
1660884 GOOD 1 1660883 3588 -6.945565 -5.285007 157.258065 FIX -1114 -979 ... -3.294052 -0.033520 0.997406 FIX 501 -389 2151 3.247167 -0.033605 0.999943
1660916 GOOD 0 1660916 3589 -6.780747 -4.868445 142.752562 FIX -1164 -983 ... -3.297369 -0.034010 0.997240 FIX 514 -400 2147 3.248033 -0.034102 0.999938
1660948 GOOD -2 1660950 3590 -6.529817 -4.373468 127.785059 FIX -1218 -1011 ... -3.300944 -0.034121 0.996956 FIX 540 -376 2156 3.249767 -0.034224 0.999956
1660984 GOOD 1 1660983 3591 -14.144531 0.861649 117.187500 SACC -2262 -392 ... -3.369811 0.007299 0.992637 SACC -435 251 2183 3.184939 0.007333 0.997358
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2786996 GOOD 0 2786996 37371 -14.786220 -3.410086 153.543307 FIX -1896 -410 ... -3.345839 -0.022103 0.995215 FIX -266 -614 1719 3.196129 -0.022170 0.998229
2787028 GOOD -2 2787030 37372 -13.598554 -3.374987 148.401826 FIX -1826 -418 ... -3.341234 -0.022643 0.995637 FIX -174 -622 1721 3.202237 -0.022709 0.998526
2787064 GOOD 1 2787063 37373 -12.725962 -6.317530 144.230769 SACC -1775 -772 ... -3.337810 -0.043592 0.995206 SACC -104 -900 1696 3.206916 -0.043718 0.998091
2787096 GOOD 0 2787096 37374 -12.933043 -8.448110 154.516640 FIX -1707 -891 ... -3.333300 -0.054413 0.995221 FIX -81 -1107 1683 3.208473 -0.054535 0.997453
2787128 GOOD -2 2787130 37375 -12.135081 -8.639768 157.258065 FIX -1609 -895 ... -3.326837 -0.054705 0.995726 FIX 6 -1111 1686 3.214250 -0.054812 0.997661
2787164 GOOD 1 2787163 37376 -11.826695 -9.233488 165.254237 FIX -1525 -879 ... -3.321294 -0.055662 0.996191 FIX 60 -1155 1651 3.217844 -0.055741 0.997608
2787196 GOOD 0 2787196 37377 -11.738032 -9.503383 172.872340 FIX -1470 -866 ... -3.317661 -0.054780 0.996487 FIX 89 -1141 1656 3.219769 -0.054848 0.997725
2787228 GOOD -1 2787229 37378 -10.801471 -9.542943 168.685121 SACC -1412 -894 ... -3.313819 -0.056383 0.996646 SACC 161 -1161 1640 3.224557 -0.056447 0.997777
2787264 GOOD 1 2787263 37379 -9.198864 -10.977843 170.454545 FIX -1261 -1000 ... -3.303797 -0.064200 0.996850 FIX 306 -1290 1617 3.234208 -0.064237 0.997411
2787296 GOOD 0 2787296 37380 -9.178187 -11.168371 175.044883 FIX -1238 -988 ... -3.302275 -0.063610 0.996976 FIX 314 -1284 1615 3.234739 -0.063640 0.997447
2787328 GOOD -2 2787330 37381 -9.300277 -11.735138 179.889299 FIX -1227 -994 ... -3.301544 -0.065039 0.996991 FIX 310 -1321 1609 3.234476 -0.065057 0.997269
2787364 GOOD 1 2787363 37382 -9.181099 -11.759391 181.564246 FIX -1210 -965 ... -3.300423 -0.064583 0.997158 FIX 322 -1336 1578 3.235275 -0.064586 0.997209
2787396 GOOD 0 2787396 37383 -9.096300 -12.025658 185.009488 FIX -1189 -973 ... -3.299029 -0.064818 0.997198 FIX 333 -1335 1580 3.236006 -0.064820 0.997224
2787428 GOOD -2 2787430 37384 -9.676554 -10.582905 183.615819 SACC -1242 -875 ... -3.302561 -0.057484 0.997365 SACC 284 -1212 1593 3.232739 -0.057506 0.997737
2787464 GOOD 1 2787463 37385 -16.579203 12.263136 210.129310 SACC -1635 933 ... -3.328463 0.058036 0.994456 SACC -176 461 1636 3.202140 0.058230 0.997781
2787496 GOOD -1 2787497 37386 -14.277263 15.237804 200.617284 FIX -1519 1204 ... -3.320712 0.075470 0.993616 FIX -38 718 1633 3.211340 0.075745 0.997242
2787528 GOOD -2 2787530 37387 -14.591146 13.275856 203.125000 FIX -1529 1044 ... -3.321434 0.064995 0.994440 FIX -54 560 1627 3.210254 0.065215 0.997809
2787564 GOOD 1 2787563 37388 -15.477176 11.046997 207.006369 FIX -1573 848 ... -3.324404 0.053106 0.995145 FIX -107 396 1630 3.206712 0.053268 0.998180
2787596 GOOD 0 2787596 37389 -16.399017 10.070586 212.882096 FIX -1607 734 ... -3.326681 0.047090 0.995432 FIX -154 328 1631 3.203583 0.047222 0.998219
2787628 GOOD -2 2787630 37390 -16.485197 8.611764 213.815789 FIX -1608 617 ... -3.326779 0.040109 0.995837 FIX -157 234 1648 3.203374 0.040213 0.998424
2787664 GOOD 0 2787664 37391 -28.826722 24.577806 145.958084 SACC -3414 2560 ... -3.440841 0.162712 0.966285 SACC -1751 2137 1736 3.100606 0.164456 0.976642
2787696 GOOD 0 2787696 37392 -466.895000 713.258197 1950.000000 SACC -4043 5641 ... -3.468119 0.333212 0.910979 SACC -3098 4980 1759 3.026497 0.336749 0.920650
2787728 GOOD -1 2787729 37393 -17.840876 36.493159 70.601014 SACC -4242 8273 ... -3.465334 0.440462 0.852134 SACC -4628 6891 1516 2.952672 0.445771 0.862405
2788664 GOOD 1 2788663 37421 106.694444 -110.851515 833.333333 FIX 1469 -2043 ... -3.124015 -0.130894 0.984004 NONE 2581 -2306 2322 3.383355 -0.130595 0.981755
2788696 GOOD 0 2788696 37422 55.923575 -60.832885 505.181347 FIX 1209 -1846 ... -3.140682 -0.118914 0.987513 FIX 2397 -2125 2343 3.371686 -0.118585 0.984782
2788728 GOOD -2 2788730 37423 21.053695 -25.140152 225.173210 FIX 951 -1729 ... -3.157431 -0.110537 0.990048 FIX 2379 -1979 2363 3.370660 -0.110091 0.986052
2788764 GOOD 1 2788763 37424 14.531137 -18.053844 175.992780 FIX 787 -1604 ... -3.168109 -0.101744 0.991819 FIX 2336 -1832 2366 3.367998 -0.101294 0.987433
2788796 GOOD 0 2788796 37425 11.155267 -15.048669 153.301887 FIX 640 -1492 ... -3.177724 -0.097502 0.993257 FIX 2271 -1812 2371 3.363791 -0.096991 0.988059
2788828 GOOD -2 2788830 37426 9.467183 -13.441365 143.805310 FIX 536 -1434 ... -3.184557 -0.092915 0.994067 FIX 2209 -1729 2394 3.359818 -0.092446 0.989058
2788864 GOOD 1 2788863 37427 11.626289 -9.802426 111.683849 SACC 1110 -1384 ... -3.146820 -0.086994 0.991166 SACC 2978 -1608 2460 3.409554 -0.086284 0.983080

18419 rows × 21 columns


In [145]:
_DEG_PER_RAD = 180. / np.pi
# df = task_df
def calc_version(df):

    fixation_pt = df.loc[:,('both', ['fixation x', 'fixation y', 'fixation z'])].values

    horz_version, vert_version = _calc_version(fixation_pt)

    cols = ['horizontal version', 'vertical version']

    version_df = pd.DataFrame(np.c_[horz_version, vert_version], index=df.index, columns=cols)

    for col in cols:
        df['both', col] = version_df[col]

    df.sortlevel(axis=1, inplace=True)


def _calc_version(fixation_pt):

    fixation_pt = np.atleast_2d(fixation_pt)
    assert fixation_pt.shape[1] == 3
    z_dir = np.array([0, 0, 1.0])

    zy_component = fixation_pt.copy()
    zy_component[:,0] = 0

    vert_version = calc_angle(z_dir, zy_component) * get_angle_direction(z_dir, zy_component, axis='x')
    horz_version = calc_angle(zy_component, fixation_pt) * get_angle_direction(fixation_pt, zy_component, axis='y')

    # flag bad/missing data with nans
    nan_inds = np.where(np.isnan(fixation_pt).any(axis=1))
    vert_version[nan_inds] = np.nan
    horz_version[nan_inds] = np.nan

    return (horz_version, vert_version)

def calc_angle(v1, v2):
    """
    Calculate the angle between two sets of vectors v1 and v2 in degrees. Inputs
    must both be Nx3 unless one argument is 1x3 or (3,).
    """

    v1, v2 = np.atleast_2d(v1, v2)  # vectors will be (1,3) or (N,3)
    assert v1.shape[1] == v2.shape[1] == 3

    v1_norm = np.sqrt(np.sum(v1**2, axis=1))
    v2_norm = np.sqrt(np.sum(v2**2, axis=1))

    v1N = v1/np.expand_dims(v1_norm, axis=1)
    v2N = v2/np.expand_dims(v2_norm, axis=1)

    cosarg = np.sum(v1N*v2N, axis=1)
    cosarg = np.min(np.c_[np.ones((cosarg.shape[0], 1)), cosarg], axis=1)

    return np.arccos(cosarg) * _DEG_PER_RAD


def get_angle_direction(v1, v2, axis):
    """
    Return the direction of rotation to get v1 onto v2 about the provided axis.
    """

    axes_dict = {'x':0, 'y':1, 'z':2, 'X':0, 'Y':1, 'Z':2}
    if axis in axes_dict:
        axis = axes_dict[axis]

    v1, v2 = np.atleast_2d(v1, v2)  # vectors will be (1,3) or (N,3)

    vec_normal = np.cross(v1, v2)

    directions = np.where(vec_normal[:,axis] == 0, np.ones(vec_normal.shape[0]), np.sign(vec_normal[:,axis]))

    return directions

def calc_vergence(df, ipd):

    fixation_pt = df.loc[:,('both', ['fixation x', 'fixation y', 'fixation z'])].values

    vergence = _calc_vergence(fixation_pt, ipd)
    vergence = pd.Series(vergence, index=df.index)
    df['both', 'vergence'] = vergence

    df.sortlevel(axis=1, inplace=True)

def _calc_vergence(fixation_pt, ipd):

    fixation_pt = np.atleast_2d(fixation_pt)
    assert fixation_pt.shape[1] == 3
    eyeref_le = fixation_pt - [-ipd/2.0, 0, 0]
    eyeref_re = fixation_pt - [ipd/2.0, 0, 0]

    vergence = calc_angle(eyeref_le, eyeref_re)

    nan_inds = np.where(np.isnan(fixation_pt).any(axis=1))
    vergence[nan_inds] = np.nan

    return vergence

In [147]:
calc_vergence(task_df, subject.ipd)

In [148]:
task_df


Out[148]:
both ... left right
quality frame_time_diff frame_time frame_count fixation x fixation y fixation z horizontal version vertical version vergence ... bref x bref y bref z flag href x href y pupil area bref x bref y bref z
rep time
1 1653668 GOOD 1 1653667 3371 -306.007813 14.105897 3046.875000 5.735113 -0.265256 0.121009 ... -3.349928 0.004606 0.994971 FIX -995 8 1403 3.147982 0.004605 0.994652
1653684 GOOD 1 1653683 3372 -282.564286 20.414063 2785.714286 5.791738 -0.419863 0.132325 ... -3.350914 0.007291 0.994882 FIX -1013 62 1416 3.146808 0.007288 0.994466
1653716 GOOD 0 1653716 3373 -5143.125000 589.706864 48750.000000 6.021990 -0.693048 0.007555 ... -3.354918 0.012030 0.994481 FIX -1037 131 1431 3.145244 0.012026 0.994202
1653748 GOOD -1 1653749 3374 -329.773438 60.198957 3046.875000 6.176071 -1.131880 0.120793 ... -3.357602 0.019642 0.994168 FIX -1112 250 1442 3.140356 0.019628 0.993452
1653784 GOOD 1 1653783 3375 -625.625000 131.791387 5416.666667 6.586537 -1.393772 0.067830 ... -3.364724 0.024167 0.993280 FIX -1171 264 1449 3.136501 0.024160 0.992989
1653816 GOOD 0 1653816 3376 -468.390000 119.054732 3900.000000 6.845263 -1.748517 0.094093 ... -3.369223 0.030304 0.992699 FIX -1233 405 1459 3.132494 0.030288 0.992169
1653848 GOOD -2 1653850 3377 -216.427966 60.696371 1652.542373 7.456400 -2.103476 0.221419 ... -3.379818 0.036407 0.991231 FIX -1362 494 1461 3.124126 0.036394 0.990877
1653884 GOOD 1 1653883 3378 -133.813776 44.601468 994.897959 7.652716 -2.566862 0.367324 ... -3.383231 0.044407 0.990565 FIX -1376 624 1469 3.123273 0.044396 0.990315
1653916 GOOD 0 1653916 3379 -92.546552 36.420227 672.413793 7.825247 -3.100306 0.542793 ... -3.386240 0.053615 0.989879 FIX -1376 788 1473 3.123358 0.053603 0.989650
1653948 GOOD -2 1653950 3380 -279.138889 137.979178 2166.666667 7.326489 -3.643829 0.168750 ... -3.377618 0.063082 0.990569 FIX -1344 921 1485 3.125515 0.063001 0.989288
1653976 GOOD -7 1653983 3381 -106.818878 62.752575 994.897959 6.116119 -3.609115 0.369348 ... -3.356643 0.062649 0.993256 SACC -969 971 1479 3.149995 0.062556 0.991787
1657048 GOOD -1 1657049 3473 NaN NaN NaN NaN NaN NaN ... NaN NaN NaN SACC 3623 -2131 1191 3.449582 NaN 0.972146
1657076 GOOD -7 1657083 3474 NaN NaN NaN NaN NaN NaN ... NaN NaN NaN SACC 3518 -1352 1550 3.443996 NaN 0.978294
1657284 GOOD 1 1657283 3480 6.013041 77.638324 108.213097 -2.585070 -35.657841 2.790080 ... -3.204599 0.586202 0.817054 FIX 476 10742 1606 3.246369 0.578981 0.806989
1660248 GOOD -2 1660250 3569 -64.262077 25.040137 471.014493 7.758265 -3.043101 0.775167 ... -3.385068 0.052630 0.989994 FIX -1710 742 2263 3.101741 0.052463 0.986858
1660284 GOOD 1 1660283 3570 -230.004098 83.386555 1598.360656 8.177680 -2.986416 0.227978 ... -3.392334 0.051602 0.989117 FIX -1676 766 2259 3.103945 0.051496 0.987081
1660316 GOOD 0 1660316 3571 -546.625000 220.523689 3750.000000 8.279300 -3.365478 0.097086 ... -3.394102 0.058135 0.988583 FIX -1669 862 2265 3.104459 0.058025 0.986717
1660348 GOOD -2 1660350 3572 -63.728261 27.187375 282.608696 12.651134 -5.495029 1.248784 ... -3.469193 0.093511 0.972032 SACC -3184 1352 2186 3.010096 0.092874 0.965408
1660384 GOOD 1 1660383 3573 -55.304426 29.453370 233.253589 13.237152 -7.196757 1.500935 ... -3.479176 0.122052 0.966580 FIX -3431 1772 2159 2.995988 0.121052 0.958658
1660416 GOOD 0 1660416 3574 -68.671829 36.875119 287.610619 13.323770 -7.306144 1.216122 ... -3.480659 0.123858 0.966043 FIX -3377 1805 2181 2.999289 0.122985 0.959232
1660448 GOOD -1 1660449 3575 -88.455993 46.652615 365.168539 13.510922 -7.280463 0.956405 ... -3.483829 0.123324 0.965306 FIX -3357 1793 2160 3.000463 0.122599 0.959634
1660484 GOOD 1 1660483 3576 -92.041506 49.441113 376.447876 13.626667 -7.482167 0.926423 ... -3.485868 0.126699 0.964695 FIX -3383 1885 2188 2.999100 0.125884 0.958487
1660516 GOOD 0 1660516 3577 -58.776418 35.544304 251.288660 13.039511 -8.050969 1.392685 ... -3.475908 0.136615 0.965830 SACC -3353 2038 2236 3.001239 0.135455 0.957633
1660784 GOOD 0 1660784 3585 -7.752935 -7.576967 190.802348 2.325008 2.274082 1.946943 ... -3.290523 -0.039603 0.997284 FIX 445 -503 2159 3.243435 -0.039704 0.999819
1660816 GOOD 0 1660816 3586 -7.549150 -8.177269 236.650485 1.826027 1.979023 1.571090 ... -3.281832 -0.034481 0.997873 FIX 477 -418 2163 3.245567 -0.034551 0.999916
1660848 GOOD -1 1660849 3587 -6.985701 -6.212841 179.889299 2.222545 1.978040 2.065719 ... -3.288735 -0.034449 0.997464 FIX 503 -375 2176 3.247300 -0.034535 0.999953
1660884 GOOD 1 1660883 3588 -6.945565 -5.285007 157.258065 2.527495 1.924828 2.361954 ... -3.294052 -0.033520 0.997406 FIX 501 -389 2151 3.247167 -0.033605 0.999943
1660916 GOOD 0 1660916 3589 -6.780747 -4.868445 142.752562 2.717928 1.953263 2.601045 ... -3.297369 -0.034010 0.997240 FIX 514 -400 2147 3.248033 -0.034102 0.999938
1660948 GOOD -2 1660950 3590 -6.529817 -4.373468 127.785059 2.923561 1.960194 2.904545 ... -3.300944 -0.034121 0.996956 FIX 540 -376 2156 3.249767 -0.034224 0.999956
1660984 GOOD 1 1660983 3591 -14.144531 0.861649 117.187500 6.882124 -0.421273 3.131544 ... -3.369811 0.007299 0.992637 SACC -435 251 2183 3.184939 0.007333 0.997358
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2786996 GOOD 0 2786996 37371 -14.786220 -3.410086 153.543307 5.499274 1.272289 2.402311 ... -3.345839 -0.022103 0.995215 FIX -266 -614 1719 3.196129 -0.022170 0.998229
2787028 GOOD -2 2787030 37372 -13.598554 -3.374987 148.401826 5.234236 1.302809 2.487645 ... -3.341234 -0.022643 0.995637 FIX -174 -622 1721 3.202237 -0.022709 0.998526
2787064 GOOD 1 2787063 37373 -12.725962 -6.317530 144.230769 5.037534 2.508040 2.559351 ... -3.337810 -0.043592 0.995206 SACC -104 -900 1696 3.206916 -0.043718 0.998091
2787096 GOOD 0 2787096 37374 -12.933043 -8.448110 154.516640 4.777403 3.129498 2.389615 ... -3.333300 -0.054413 0.995221 FIX -81 -1107 1683 3.208473 -0.054535 0.997453
2787128 GOOD -2 2787130 37375 -12.135081 -8.639768 157.258065 4.405961 3.144672 2.350380 ... -3.326837 -0.054705 0.995726 FIX 6 -1111 1686 3.214250 -0.054812 0.997661
2787164 GOOD 1 2787163 37376 -11.826695 -9.233488 165.254237 4.087136 3.198044 2.238414 ... -3.321294 -0.055662 0.996191 FIX 60 -1155 1651 3.217844 -0.055741 0.997608
2787196 GOOD 0 2787196 37377 -11.738032 -9.503383 172.872340 3.878583 3.146577 2.140985 ... -3.317661 -0.054780 0.996487 FIX 89 -1141 1656 3.219769 -0.054848 0.997725
2787228 GOOD -1 2787229 37378 -10.801471 -9.542943 168.685121 3.658005 3.237916 2.195035 ... -3.313819 -0.056383 0.996646 SACC 161 -1161 1640 3.224557 -0.056447 0.997777
2787264 GOOD 1 2787263 37379 -9.198864 -10.977843 170.454545 3.082691 3.684951 2.173798 ... -3.303797 -0.064200 0.996850 FIX 306 -1290 1617 3.234208 -0.064237 0.997411
2787296 GOOD 0 2787296 37380 -9.178187 -11.168371 175.044883 2.995381 3.650688 2.117229 ... -3.302275 -0.063610 0.996976 FIX 314 -1284 1615 3.234739 -0.063640 0.997447
2787328 GOOD -2 2787330 37381 -9.300277 -11.735138 179.889299 2.953291 3.732420 2.060192 ... -3.301544 -0.065039 0.996991 FIX 310 -1321 1609 3.234476 -0.065057 0.997269
2787364 GOOD 1 2787363 37382 -9.181099 -11.759391 181.564246 2.888749 3.705706 2.041487 ... -3.300423 -0.064583 0.997158 FIX 322 -1336 1578 3.235275 -0.064586 0.997209
2787396 GOOD 0 2787396 37383 -9.096300 -12.025658 185.009488 2.808858 3.719007 2.003726 ... -3.299029 -0.064818 0.997198 FIX 333 -1335 1580 3.236006 -0.064820 0.997224
2787428 GOOD -2 2787430 37384 -9.676554 -10.582905 183.615819 3.011708 3.298658 2.019113 ... -3.302561 -0.057484 0.997365 SACC 284 -1212 1593 3.232739 -0.057506 0.997737
2787464 GOOD 1 2787463 37385 -16.579203 12.263136 210.129310 4.503660 -3.339990 1.758294 ... -3.328463 0.058036 0.994456 SACC -176 461 1636 3.202140 0.058230 0.997781
2787496 GOOD -1 2787497 37386 -14.277263 15.237804 200.617284 4.059034 -4.343538 1.841621 ... -3.320712 0.075470 0.993616 FIX -38 718 1633 3.211340 0.075745 0.997242
2787528 GOOD -2 2787530 37387 -14.591146 13.275856 203.125000 4.099972 -3.739423 1.820058 ... -3.321434 0.064995 0.994440 FIX -54 560 1627 3.210254 0.065215 0.997809
2787564 GOOD 1 2787563 37388 -15.477176 11.046997 207.006369 4.269806 -3.054720 1.786430 ... -3.324404 0.053106 0.995145 FIX -107 396 1630 3.206712 0.053268 0.998180
2787596 GOOD 0 2787596 37389 -16.399017 10.070586 212.882096 4.400084 -2.708411 1.737061 ... -3.326681 0.047090 0.995432 FIX -154 328 1631 3.203583 0.047222 0.998219
2787628 GOOD -2 2787630 37390 -16.485197 8.611764 213.815789 4.405225 -2.306430 1.729984 ... -3.326779 0.040109 0.995837 FIX -157 234 1648 3.203374 0.040213 0.998424
2787664 GOOD 0 2787664 37391 -28.826722 24.577806 145.958084 11.020857 -9.558338 2.423877 ... -3.440841 0.162712 0.966285 SACC -1751 2137 1736 3.100606 0.164456 0.976642
2787696 GOOD 0 2787696 37392 -466.895000 713.258197 1950.000000 12.672919 -20.091177 0.170731 ... -3.468119 0.333212 0.910979 SACC -3098 4980 1759 3.026497 0.336749 0.920650
2787728 GOOD -1 2787729 37393 -17.840876 36.493159 70.601014 12.652269 -27.334119 4.459314 ... -3.465334 0.440462 0.852134 SACC -4628 6891 1516 2.952672 0.445771 0.862405
2788664 GOOD 1 2788663 37421 106.694444 -110.851515 833.333333 -7.233046 7.577106 0.435980 ... -3.124015 -0.130894 0.984004 NONE 2581 -2306 2322 3.383355 -0.130595 0.981755
2788696 GOOD 0 2788696 37422 55.923575 -60.832885 505.181347 -6.271978 6.866377 0.723173 ... -3.140682 -0.118914 0.987513 FIX 2397 -2125 2343 3.371686 -0.118585 0.984782
2788728 GOOD -2 2788730 37423 21.053695 -25.140152 225.173210 -5.308830 6.370580 1.629547 ... -3.157431 -0.110537 0.990048 FIX 2379 -1979 2363 3.370660 -0.110091 0.986052
2788764 GOOD 1 2788763 37424 14.531137 -18.053844 175.992780 -4.695485 5.857077 2.090743 ... -3.168109 -0.101744 0.991819 FIX 2336 -1832 2366 3.367998 -0.101294 0.987433
2788796 GOOD 0 2788796 37425 11.155267 -15.048669 153.301887 -4.142049 5.606400 2.404759 ... -3.177724 -0.097502 0.993257 FIX 2271 -1812 2371 3.363791 -0.096991 0.988059
2788828 GOOD -2 2788830 37426 9.467183 -13.441365 143.805310 -3.750238 5.339875 2.567075 ... -3.184557 -0.092915 0.994067 FIX 2209 -1729 2394 3.359818 -0.092446 0.989058
2788864 GOOD 1 2788863 37427 11.626289 -9.802426 111.683849 -5.920487 5.015963 3.285629 ... -3.146820 -0.086994 0.991166 SACC 2978 -1608 2460 3.409554 -0.086284 0.983080

18419 rows × 24 columns


In [141]:
32/8./1024/1024 * 7000*207*207


Out[141]:
1144.1917419433594

In [136]:
task_df


Out[136]:
both left right
quality frame_time_diff frame_time frame_count fixation x fixation y fixation z horizontal version vertical version flag ... bref x bref y bref z flag href x href y pupil area bref x bref y bref z
rep time
1 1653668 GOOD 1 1653667 3371 -306.007813 14.105897 3046.875000 5.735113 -0.265256 FIX ... -3.349928 0.004606 0.994971 FIX -995 8 1403 3.147982 0.004605 0.994652
1653684 GOOD 1 1653683 3372 -282.564286 20.414063 2785.714286 5.791738 -0.419863 FIX ... -3.350914 0.007291 0.994882 FIX -1013 62 1416 3.146808 0.007288 0.994466
1653716 GOOD 0 1653716 3373 -5143.125000 589.706864 48750.000000 6.021990 -0.693048 FIX ... -3.354918 0.012030 0.994481 FIX -1037 131 1431 3.145244 0.012026 0.994202
1653748 GOOD -1 1653749 3374 -329.773438 60.198957 3046.875000 6.176071 -1.131880 FIX ... -3.357602 0.019642 0.994168 FIX -1112 250 1442 3.140356 0.019628 0.993452
1653784 GOOD 1 1653783 3375 -625.625000 131.791387 5416.666667 6.586537 -1.393772 FIX ... -3.364724 0.024167 0.993280 FIX -1171 264 1449 3.136501 0.024160 0.992989
1653816 GOOD 0 1653816 3376 -468.390000 119.054732 3900.000000 6.845263 -1.748517 FIX ... -3.369223 0.030304 0.992699 FIX -1233 405 1459 3.132494 0.030288 0.992169
1653848 GOOD -2 1653850 3377 -216.427966 60.696371 1652.542373 7.456400 -2.103476 FIX ... -3.379818 0.036407 0.991231 FIX -1362 494 1461 3.124126 0.036394 0.990877
1653884 GOOD 1 1653883 3378 -133.813776 44.601468 994.897959 7.652716 -2.566862 FIX ... -3.383231 0.044407 0.990565 FIX -1376 624 1469 3.123273 0.044396 0.990315
1653916 GOOD 0 1653916 3379 -92.546552 36.420227 672.413793 7.825247 -3.100306 FIX ... -3.386240 0.053615 0.989879 FIX -1376 788 1473 3.123358 0.053603 0.989650
1653948 GOOD -2 1653950 3380 -279.138889 137.979178 2166.666667 7.326489 -3.643829 SACC ... -3.377618 0.063082 0.990569 FIX -1344 921 1485 3.125515 0.063001 0.989288
1653976 GOOD -7 1653983 3381 -106.818878 62.752575 994.897959 6.116119 -3.609115 SACC ... -3.356643 0.062649 0.993256 SACC -969 971 1479 3.149995 0.062556 0.991787
1657048 GOOD -1 1657049 3473 NaN NaN NaN NaN NaN BLINK ... NaN NaN NaN SACC 3623 -2131 1191 3.449582 NaN 0.972146
1657076 GOOD -7 1657083 3474 NaN NaN NaN NaN NaN BLINK ... NaN NaN NaN SACC 3518 -1352 1550 3.443996 NaN 0.978294
1657284 GOOD 1 1657283 3480 6.013041 77.638324 108.213097 -2.585070 -35.657841 NONE ... -3.204599 0.586202 0.817054 FIX 476 10742 1606 3.246369 0.578981 0.806989
1660248 GOOD -2 1660250 3569 -64.262077 25.040137 471.014493 7.758265 -3.043101 FIX ... -3.385068 0.052630 0.989994 FIX -1710 742 2263 3.101741 0.052463 0.986858
1660284 GOOD 1 1660283 3570 -230.004098 83.386555 1598.360656 8.177680 -2.986416 FIX ... -3.392334 0.051602 0.989117 FIX -1676 766 2259 3.103945 0.051496 0.987081
1660316 GOOD 0 1660316 3571 -546.625000 220.523689 3750.000000 8.279300 -3.365478 FIX ... -3.394102 0.058135 0.988583 FIX -1669 862 2265 3.104459 0.058025 0.986717
1660348 GOOD -2 1660350 3572 -63.728261 27.187375 282.608696 12.651134 -5.495029 SACC ... -3.469193 0.093511 0.972032 SACC -3184 1352 2186 3.010096 0.092874 0.965408
1660384 GOOD 1 1660383 3573 -55.304426 29.453370 233.253589 13.237152 -7.196757 FIX ... -3.479176 0.122052 0.966580 FIX -3431 1772 2159 2.995988 0.121052 0.958658
1660416 GOOD 0 1660416 3574 -68.671829 36.875119 287.610619 13.323770 -7.306144 FIX ... -3.480659 0.123858 0.966043 FIX -3377 1805 2181 2.999289 0.122985 0.959232
1660448 GOOD -1 1660449 3575 -88.455993 46.652615 365.168539 13.510922 -7.280463 FIX ... -3.483829 0.123324 0.965306 FIX -3357 1793 2160 3.000463 0.122599 0.959634
1660484 GOOD 1 1660483 3576 -92.041506 49.441113 376.447876 13.626667 -7.482167 FIX ... -3.485868 0.126699 0.964695 FIX -3383 1885 2188 2.999100 0.125884 0.958487
1660516 GOOD 0 1660516 3577 -58.776418 35.544304 251.288660 13.039511 -8.050969 FIX ... -3.475908 0.136615 0.965830 SACC -3353 2038 2236 3.001239 0.135455 0.957633
1660784 GOOD 0 1660784 3585 -7.752935 -7.576967 190.802348 2.325008 2.274082 FIX ... -3.290523 -0.039603 0.997284 FIX 445 -503 2159 3.243435 -0.039704 0.999819
1660816 GOOD 0 1660816 3586 -7.549150 -8.177269 236.650485 1.826027 1.979023 FIX ... -3.281832 -0.034481 0.997873 FIX 477 -418 2163 3.245567 -0.034551 0.999916
1660848 GOOD -1 1660849 3587 -6.985701 -6.212841 179.889299 2.222545 1.978040 FIX ... -3.288735 -0.034449 0.997464 FIX 503 -375 2176 3.247300 -0.034535 0.999953
1660884 GOOD 1 1660883 3588 -6.945565 -5.285007 157.258065 2.527495 1.924828 FIX ... -3.294052 -0.033520 0.997406 FIX 501 -389 2151 3.247167 -0.033605 0.999943
1660916 GOOD 0 1660916 3589 -6.780747 -4.868445 142.752562 2.717928 1.953263 FIX ... -3.297369 -0.034010 0.997240 FIX 514 -400 2147 3.248033 -0.034102 0.999938
1660948 GOOD -2 1660950 3590 -6.529817 -4.373468 127.785059 2.923561 1.960194 FIX ... -3.300944 -0.034121 0.996956 FIX 540 -376 2156 3.249767 -0.034224 0.999956
1660984 GOOD 1 1660983 3591 -14.144531 0.861649 117.187500 6.882124 -0.421273 SACC ... -3.369811 0.007299 0.992637 SACC -435 251 2183 3.184939 0.007333 0.997358
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2786996 GOOD 0 2786996 37371 -14.786220 -3.410086 153.543307 5.499274 1.272289 FIX ... -3.345839 -0.022103 0.995215 FIX -266 -614 1719 3.196129 -0.022170 0.998229
2787028 GOOD -2 2787030 37372 -13.598554 -3.374987 148.401826 5.234236 1.302809 FIX ... -3.341234 -0.022643 0.995637 FIX -174 -622 1721 3.202237 -0.022709 0.998526
2787064 GOOD 1 2787063 37373 -12.725962 -6.317530 144.230769 5.037534 2.508040 SACC ... -3.337810 -0.043592 0.995206 SACC -104 -900 1696 3.206916 -0.043718 0.998091
2787096 GOOD 0 2787096 37374 -12.933043 -8.448110 154.516640 4.777403 3.129498 FIX ... -3.333300 -0.054413 0.995221 FIX -81 -1107 1683 3.208473 -0.054535 0.997453
2787128 GOOD -2 2787130 37375 -12.135081 -8.639768 157.258065 4.405961 3.144672 FIX ... -3.326837 -0.054705 0.995726 FIX 6 -1111 1686 3.214250 -0.054812 0.997661
2787164 GOOD 1 2787163 37376 -11.826695 -9.233488 165.254237 4.087136 3.198044 FIX ... -3.321294 -0.055662 0.996191 FIX 60 -1155 1651 3.217844 -0.055741 0.997608
2787196 GOOD 0 2787196 37377 -11.738032 -9.503383 172.872340 3.878583 3.146577 FIX ... -3.317661 -0.054780 0.996487 FIX 89 -1141 1656 3.219769 -0.054848 0.997725
2787228 GOOD -1 2787229 37378 -10.801471 -9.542943 168.685121 3.658005 3.237916 SACC ... -3.313819 -0.056383 0.996646 SACC 161 -1161 1640 3.224557 -0.056447 0.997777
2787264 GOOD 1 2787263 37379 -9.198864 -10.977843 170.454545 3.082691 3.684951 FIX ... -3.303797 -0.064200 0.996850 FIX 306 -1290 1617 3.234208 -0.064237 0.997411
2787296 GOOD 0 2787296 37380 -9.178187 -11.168371 175.044883 2.995381 3.650688 FIX ... -3.302275 -0.063610 0.996976 FIX 314 -1284 1615 3.234739 -0.063640 0.997447
2787328 GOOD -2 2787330 37381 -9.300277 -11.735138 179.889299 2.953291 3.732420 FIX ... -3.301544 -0.065039 0.996991 FIX 310 -1321 1609 3.234476 -0.065057 0.997269
2787364 GOOD 1 2787363 37382 -9.181099 -11.759391 181.564246 2.888749 3.705706 FIX ... -3.300423 -0.064583 0.997158 FIX 322 -1336 1578 3.235275 -0.064586 0.997209
2787396 GOOD 0 2787396 37383 -9.096300 -12.025658 185.009488 2.808858 3.719007 FIX ... -3.299029 -0.064818 0.997198 FIX 333 -1335 1580 3.236006 -0.064820 0.997224
2787428 GOOD -2 2787430 37384 -9.676554 -10.582905 183.615819 3.011708 3.298658 SACC ... -3.302561 -0.057484 0.997365 SACC 284 -1212 1593 3.232739 -0.057506 0.997737
2787464 GOOD 1 2787463 37385 -16.579203 12.263136 210.129310 4.503660 -3.339990 SACC ... -3.328463 0.058036 0.994456 SACC -176 461 1636 3.202140 0.058230 0.997781
2787496 GOOD -1 2787497 37386 -14.277263 15.237804 200.617284 4.059034 -4.343538 FIX ... -3.320712 0.075470 0.993616 FIX -38 718 1633 3.211340 0.075745 0.997242
2787528 GOOD -2 2787530 37387 -14.591146 13.275856 203.125000 4.099972 -3.739423 FIX ... -3.321434 0.064995 0.994440 FIX -54 560 1627 3.210254 0.065215 0.997809
2787564 GOOD 1 2787563 37388 -15.477176 11.046997 207.006369 4.269806 -3.054720 FIX ... -3.324404 0.053106 0.995145 FIX -107 396 1630 3.206712 0.053268 0.998180
2787596 GOOD 0 2787596 37389 -16.399017 10.070586 212.882096 4.400084 -2.708411 FIX ... -3.326681 0.047090 0.995432 FIX -154 328 1631 3.203583 0.047222 0.998219
2787628 GOOD -2 2787630 37390 -16.485197 8.611764 213.815789 4.405225 -2.306430 FIX ... -3.326779 0.040109 0.995837 FIX -157 234 1648 3.203374 0.040213 0.998424
2787664 GOOD 0 2787664 37391 -28.826722 24.577806 145.958084 11.020857 -9.558338 SACC ... -3.440841 0.162712 0.966285 SACC -1751 2137 1736 3.100606 0.164456 0.976642
2787696 GOOD 0 2787696 37392 -466.895000 713.258197 1950.000000 12.672919 -20.091177 SACC ... -3.468119 0.333212 0.910979 SACC -3098 4980 1759 3.026497 0.336749 0.920650
2787728 GOOD -1 2787729 37393 -17.840876 36.493159 70.601014 12.652269 -27.334119 SACC ... -3.465334 0.440462 0.852134 SACC -4628 6891 1516 2.952672 0.445771 0.862405
2788664 GOOD 1 2788663 37421 106.694444 -110.851515 833.333333 -7.233046 7.577106 FIX ... -3.124015 -0.130894 0.984004 NONE 2581 -2306 2322 3.383355 -0.130595 0.981755
2788696 GOOD 0 2788696 37422 55.923575 -60.832885 505.181347 -6.271978 6.866377 FIX ... -3.140682 -0.118914 0.987513 FIX 2397 -2125 2343 3.371686 -0.118585 0.984782
2788728 GOOD -2 2788730 37423 21.053695 -25.140152 225.173210 -5.308830 6.370580 FIX ... -3.157431 -0.110537 0.990048 FIX 2379 -1979 2363 3.370660 -0.110091 0.986052
2788764 GOOD 1 2788763 37424 14.531137 -18.053844 175.992780 -4.695485 5.857077 FIX ... -3.168109 -0.101744 0.991819 FIX 2336 -1832 2366 3.367998 -0.101294 0.987433
2788796 GOOD 0 2788796 37425 11.155267 -15.048669 153.301887 -4.142049 5.606400 FIX ... -3.177724 -0.097502 0.993257 FIX 2271 -1812 2371 3.363791 -0.096991 0.988059
2788828 GOOD -2 2788830 37426 9.467183 -13.441365 143.805310 -3.750238 5.339875 FIX ... -3.184557 -0.092915 0.994067 FIX 2209 -1729 2394 3.359818 -0.092446 0.989058
2788864 GOOD 1 2788863 37427 11.626289 -9.802426 111.683849 -5.920487 5.015963 SACC ... -3.146820 -0.086994 0.991166 SACC 2978 -1608 2460 3.409554 -0.086284 0.983080

18419 rows × 23 columns

Testing for 3d plot


In [169]:
task_df = session_gaze_data[~np.isnan(session_gaze_data['both', 'frame_time'])].copy()
convert_href_to_bref(task_df, rt_data.copy())
task_df.sortlevel(axis=1, inplace=True)

fix_L = task_df.loc[:, ('left', ['bref x', 'bref y', 'bref z'])].copy()
fix_R = task_df.loc[:, ('right', ['bref x', 'bref y', 'bref z'])].copy()

In [170]:
ipd = 6.5
loc_L = np.array([[-ipd/2, 0, 0.]]).T
loc_R = np.array([[ipd/2, 0, 0.]]).T

In [175]:
import time
t1 = time.time()
for i in xrange(2):#len(fix_L)):
    aligned = fit_plane(np.atleast_2d(fix_L.values[i]).T, np.atleast_2d(fix_R.values[i]).T, ipd, plot_results=True)
t2 = time.time()

print t2-t1


0.132351875305

In [122]:
aligned


Out[122]:
(array([[ -3.29845944e+00],
        [  1.50194326e-03],
        [  9.98820455e-01]]), array([[  3.27637367e+00],
        [  1.50316624e-03],
        [  9.99633759e-01]]))

In [14]:
href_z = 15000

df = session_gaze_data.ix[[]]

fix_L = session_gaze_data['left'][['href x', 'href y']]
fix_L['href z'] = 15000

fix_R = session_gaze_data['right'][['href x', 'href y']]
fix_R['href z'] = 15000

In [92]:
df = session_gaze_data.loc[:, (['left', 'right'], ['href x', 'href y'])].copy()

In [96]:
df[('left', 'href z')] = 15000
df[('right', 'href z')] = 15000
df.sortlevel(axis=1, inplace=True)

In [159]:
Z = np.array([[1, 2, 3, 4]]).T

In [212]:
fix_L = task_df.loc[:, ('left', ['bref x', 'bref y', 'bref z'])]

In [173]:
%matplotlib inline
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d

In [ ]:
super()